<?php

namespace App\Http\Controllers\Personnel;

use App\Criteria\Personnel\Station\StationClassBaseQueryCriteria;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CurlRecordMethod;
use App\Http\Requests\Personnel\StationClassBaseRequest;
use App\Libs\Tools\ZTree;
use App\Repositories\Personnel\StationClassRepository;
use App\Validators\Personnel\StationClassValidator;
use Illuminate\Support\Facades\Input;
use Prettus\Validator\Exceptions\ValidatorException;


class StationClassesController extends Controller
{

    use CurlRecordMethod;

    protected $index_page='personnel.stationClass.stationClassMain';
    protected $add_page='personnel.stationClass.stationClassAdd';
    protected $edit_page='personnel.stationClass.stationClassEdit';

    protected $repository;
    protected $validator;
    protected $request;

    public function __construct(StationClassRepository $repository, StationClassValidator $validator,StationClassBaseRequest $request){
        $this->repository = $repository;
        $this->validator  = $validator;
        $this->request    = $request;
    }

    public function list_tree_data(){
        $allStationClass=$this->repository->all();
        $tree_data=ZTree::convert_station_class_transform_to_tree($allStationClass);
        return response()->json($tree_data);
    }

    public function getBaseQueryCriteria(){
        return new StationClassBaseQueryCriteria;
    }

    public function delete_data(){
        try {
            $this->validator->with(Input::all())->passesOrFail('DELETE');
            $this->repository->deleteByPrimaryKeys(Input::get('id'));
            return $this->return_json_success();
        } catch (ValidatorException $e) {
            return $this->return_json_error($e);
        }
    }
}
